//
//  LMmicoBlogCell.m
//  14微博
//
//  Created by apple on 15/8/2.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "LMmicroBlogCell.h"
#import "LMmicroBlog.h"
#import "LMmicroBlogCell.h"
#import "LMmicroBlogFrame.h"
@interface LMmicroBlogCell ()
@property (nonatomic,weak) UIImageView *iconView;
@property (nonatomic,weak) UILabel *nameView;
@property (nonatomic,weak) UIImageView *vipView;
@property (nonatomic,weak) UILabel *textView;
@property (nonatomic,weak) UIImageView *pictureView;

@end


@implementation LMmicroBlogCell

+ (instancetype)microBlogCellWithTableView:(UITableView *)tableView
{
    static NSString *reuseId =@"blog";
    LMmicroBlogCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    
    if (cell==nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        UIImageView *iconView = [[UIImageView alloc] init];
        [self.contentView addSubview:iconView];
        self.iconView = iconView;
        
        UILabel *nameView = [[UILabel alloc] init];
        [self.contentView addSubview:nameView];
        nameView.font = [UIFont systemFontOfSize:12];
        self.nameView = nameView;
        
        UIImageView *vipView = [[UIImageView alloc] init];
        vipView.image = [UIImage imageNamed:@"vip"];
        [self.contentView addSubview:vipView];
        self.vipView = vipView;
        
        UILabel *textView = [[UILabel alloc] init];
        textView.numberOfLines = 0;
        textView.lineBreakMode = NSLineBreakByWordWrapping;
        textView.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:textView];
       
        self.textView = textView;
        
        UIImageView *pictureView = [[UIImageView alloc] init];
        [self.contentView addSubview:pictureView];
        self.pictureView = pictureView;
        
    }
    return  self;
}

- (void)setMicroBlogFrame:(LMmicroBlogFrame *)microBlogFrame
{
    _microBlogFrame = microBlogFrame;
    [self addSubViewContent];
    [self addSubViewFrame];
}

//设置内容
- (void) addSubViewContent
{
    LMmicroBlog *blog = self.microBlogFrame.microBlog;
    self.iconView.image = [UIImage imageNamed:blog.icon];
    self.nameView.text =blog.name;

    if (!blog.isVip) {
        self.vipView.hidden = YES;
        self.nameView.textColor = [UIColor redColor];
    }
    else
    {
        self.vipView.hidden = NO;
        self.nameView.textColor = [UIColor blackColor];
    }
    
    self.textView.text =blog.text;
    
    if (blog.picture!=nil) {
        self.pictureView.image = [UIImage imageNamed:blog.picture];

    }
 
}

//设置子控件

- (void) addSubViewFrame
{
    self.iconView.frame = self.microBlogFrame.iconFrame;
    self.nameView.frame = self.microBlogFrame.nameFrame;
    self.vipView.frame = self.microBlogFrame.vipFrame;
    self.textView.frame = self.microBlogFrame.textFrame;
    self.pictureView.frame = self.microBlogFrame.pictureFrame;
}





@end
